package com.wxapp.system.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.system.api.pojo.vm.dict.key.PDictKeyDetailVm;
import com.wxapp.system.api.pojo.vm.dict.key.PDictKeyPageVm;
import com.wxapp.system.api.pojo.vm.dict.key.QDictKeySelectVm;
import com.wxapp.system.api.pojo.vo.dict.key.QDictKeyPageVo;
import com.wxapp.system.api.pojo.vo.dict.key.QDictKeySaveVo;
import com.wxapp.system.api.pojo.vo.dict.key.QDictKeyUpdateVo;
import com.wxapp.system.service.service.DictKeyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 字典类
 * @Datetime 2022/5/30 9:29
 * @Modified By
 */
@RestController
@RequestMapping("/dict/key")
@Tag(name = "字典管理")
@RequiredArgsConstructor
public class DictKeyController extends IBaseController {
    private final DictKeyService dictKeyService;

    @PostMapping("/save")
    @Operation(summary ="保存字典key信息")
    public ResultVm<String> saveDictKey(@Schema(hidden = true) @User UserVo userVo, @RequestBody QDictKeySaveVo qDictKeySaveVo) {
        return dictKeyService.saveDictKey(userVo, qDictKeySaveVo);
    }

    @PutMapping("/update")
    @Operation(summary ="更新字典key信息")
    public ResultVm<String> updateDictKey(@Schema(hidden = true) @User UserVo userVo, @RequestBody QDictKeyUpdateVo qSaveVo) {
        return dictKeyService.updateDictKey(userVo, qSaveVo);
    }

    @GetMapping("/detail")
    @Operation(summary ="得到字典key详情")
    public ResultVm<PDictKeyDetailVm> detailDictKey(@RequestParam String id) {
        return dictKeyService.detailDictKey(id);
    }


    @PostMapping("/page")
    @Operation(summary ="更新字典key信息")
    public ResultVm<Page<PDictKeyPageVm>> pageDictKey(@RequestBody QDictKeyPageVo qSaveVo) {
        return dictKeyService.pageDictKey(qSaveVo);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary ="删除字典key")
    public ResultVm<String> deleteDictKey(@PathVariable String id) {
        return dictKeyService.deleteDictKey(id);
    }

    @GetMapping("/select")
    @Operation(summary ="得到字典列表")
    public ResultVm<List<QDictKeySelectVm>> getSelect(@RequestParam(value = "pid", required = false) String pid) {
        return dictKeyService.getSelect(pid);
    }
}
